//设置字段是否disabled
const setDisadledFn = (sourceList, filedList, isDisabled) => {
	sourceList.forEach(item => {
		if (filedList.indexOf(item.bindFieldName) > -1) {
			console.log(item.bindFieldName);
			item.isDisabled = isDisabled;
		}
	});
};

//隐藏某字段
const setIsHideFn = (sourceList, filedList, isHide) => {
	sourceList.forEach(item => {
		if (filedList.indexOf(item.bindFieldName) > -1) {
			item.isHide = isHide;
		}
	});
};

// 赋值下拉框的optionList
const setFormSelectOptions = (sourceList, filedName, optionList) => {
	sourceList.forEach((item, index) => {
		if (item.bindFieldName == filedName) {
			item.optionList = optionList || [];
		}
	});
};

//设置一些字段的必填与否 filedList:需要控制哪些字段 Ex:["filed1,filed2"]  isRequired:是否加校验 Ex:true false
const setValidateFn = (sourceList, filedList, isRequired) => {
	sourceList.forEach(item => {
		if (filedList.indexOf(item.bindFieldName) > -1) {
			item.isRequired = isRequired;
		}
	});
};

//select 联想查询
const remoteMethod = async (sourceList, value, formItem) => {
	if (formItem.optionMethod && formItem.optionMethod.link) {
		let param = {};
		param[formItem.optionMethod.keyName] = value || '';
		let res = await formItem.optionMethod.link(param);
		setFormSelectOptions(sourceList, formItem.bindFieldName, res.rows || []);
	}
};

export { setDisadledFn, setIsHideFn, setFormSelectOptions, setValidateFn, remoteMethod };
